//
//  RootViewController.m
//  CarStore
//
//  Created by 千锋 on 16/1/25.
//  Copyright (c) 2016年 1000phone. All rights reserved.
//

#import "RootViewController.h"
/** 四个视图控制器*/
#import "HomeViewController.h"
#import "ManagerViewController.h"
#import "BankViewController.h"
#import "MyViewController.h"


@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tabBar.tintColor = [UIColor whiteColor];
    [self setUpControllers];
    
    self.tabBar.barTintColor = [UIColor colorWithWhite:0.95 alpha:1];
    self.tabBar.tintColor = MAIN_COLOR;
    self.tabBar.translucent = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/** 设置子视图控制器*/
- (void)setUpControllers
{
    NSArray *classArray = @[@"HomeViewController",@"ManagerViewController",@"BankViewController",@"MyViewController"];
    NSArray *titleArr = @[@"咔咔车",@"我的管家",@"汽车金融",@"关于我"];
    NSArray *images = @[@"home", @"manager",
                        @"money", @"profile"];
    
    for (int i = 0; i < classArray.count; i++) {
        UIViewController *vc;
        if (i == classArray.count - 1 || i== 2) {
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            vc = [sb instantiateViewControllerWithIdentifier:classArray[i]];
        }else{
            Class class = NSClassFromString(classArray[i]);
            vc = [[class alloc]init];
        }
        [self setUpOneChildController:vc title:titleArr[i] image:[NSString stringWithFormat:@"tabbar_%@",images[i]] selectedImage:[NSString stringWithFormat:@"tabbar_%@_selected",images[i]]];
    }
}
// 设置一个视图控制器
- (void)setUpOneChildController:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selImage
{
    vc.title = title;
    vc.tabBarItem.image = [UIImage originalImageWithString:image];
    vc.tabBarItem.selectedImage = [UIImage originalImageWithString:selImage];
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
    
    nav.navigationBar.barTintColor = MAIN_COLOR;
    nav.navigationBar.translucent = NO;
    
    [self addChildViewController:nav];
}


@end
